<?php
namespace App\Services\Fund\FundUnfreezeLog;
use App\Services\Fund\ValidateFundUnfreezeLog;
use App\Models\Fund\FundUnfreezeLog;
use Illuminate\Support\Facades\DB;
class FundUnfreezeLogLogic
{
     // 所有用户资金解冻日志分页数据
    public function list(array $data): array
    {
        $query = FundUnfreezeLog::where('status','=',1);
        $data['keywords'] != '' && $query->where('user_id','like',"%{$data['keywords']}%");
        if($data['startTime'] != ''){
            if($data['endTime'] != ''){
                $query->whereBetween('create_time', [$data['startTime'], $data['endTime']]);
            }else{
               $query->where('create_time','>=',$data['startTime']); 
            }
        }else{
            $data['endTime'] != '' &&  $query->where('create_time','<=',$data['endTime']);
        } 
         $res = $query->orderBy('id', 'desc')
                      ->paginate($data['list_rows'], null, null, $data['page'])
                      ->toArray();
        return auto_return_page($res, '已找到用户资金解冻日志', '没有用户资金解冻日志');
    }
    // 获取某些user_ids的的资金解冻日志(分页)
    public function listByUserIds(array $data): array
    {
        $where['status'] = 1;
        $res = FundUnfreezeLog::where($where)
                     ->whereIn('user_id',[$data['user_ids']])
                     ->orderBy('id', 'desc')
                     ->paginate($data['list_rows'], null, null, $data['page'])
                     ->toArray();            
        return auto_return_page($res, '已找到用户资金解冻日志', '没有用户资金解冻日志');
    }
    // 获取某个冻结日志的资金解冻日志
    public function listByFreezeId(array $data): array
    {
        $where['status'] = 1;
        $where['freeze_log_id'] = $data['freeze_log_id'];
        $res = FundUnfreezeLog::where($where)
                     ->orderBy('id', 'desc')
                     ->paginate($data['list_rows'], null, null, $data['page'])
                     ->toArray();      
        return auto_return_page($res, '已找到资金解冻日志', '没有资金解冻日志');
    }
}